<?php
session_start();
    if(!isset($_SESSION['usuario'])){
            header('location:../html/login.html');
         }
         
         echo '
                <center>
                    <title>Identificacion de Necesidades</title>
                    <table>
                        <tr>
                            <td>';
                         include_once 'menu.php';
                        echo"</td>
                        </tr>
                    </table>
                    </br>";
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="jquery-1.9.1.min.js"></script>
        <!-- Librerias jquery y hojas de estilo para creacion  del calendario -->
        <script src="../reportes/js/jquery-1.5.2.js" type="text/javascript"></script>
        <link rel="stylesheet" href="../reportes/css/impresion.css" type="text/css" media="print">
        <link rel="stylesheet" href="../reportes/css/jquery.ui.all.css" type="text/css">
        <script type="text/javascript" src="../reportes/js/jquery.ui.core.js"></script>
        <script type="text/javascript" src="../reportes/js/jquery.ui.widget.js"></script>
        <script type="text/javascript" src="../reportes/js/jquery.ui.datepicker.js"></script>
        <link rel="stylesheet" href="../reportes/css/pestana.css" />
        <script src="../reportes/js/jquery-ui.js"></script>
        
        <script type="text/javascript" src="../../Ginecobstetricia/vista/js/alertify.js"></script>
        <link rel="stylesheet" href="../../Ginecobstetricia/vista/css/alertify.core.css" />
        <link rel="stylesheet" href="../../Ginecobstetricia/vista/css/alertify.default.css" />
        
        <style>
            
            label,input,button,select,textarea{font-size:14px;font-weight:normal;line-height:20px}input,button,select,textarea{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif}label{display:block;margin-bottom:5px}select,textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{display:inline-block;height:28px;padding:4px 6px;margin-bottom:10px;font-size:14px;line-height:20px;color:#555;vertical-align:middle;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}input,textarea,.uneditable-input{width:170px}textarea{height:auto}textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{background-color:#fff;border:1px solid #ccc;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border linear .2s,box-shadow linear .2s;-moz-transition:border linear .2s,box-shadow linear .2s;-o-transition:border linear .2s,box-shadow linear .2s;transition:border linear .2s,box-shadow linear .2s}textarea:focus,input[type="text"]:focus,input[type="password"]:focus,input[type="datetime"]:focus,input[type="datetime-local"]:focus,input[type="date"]:focus,input[type="month"]:focus,input[type="time"]:focus,input[type="week"]:focus,input[type="number"]:focus,input[type="email"]:focus,input[type="url"]:focus,input[type="search"]:focus,input[type="tel"]:focus,input[type="color"]:focus,.uneditable-input:focus{border-color:rgba(82,168,236,0.8);outline:0;outline:thin dotted \9;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6)}input[type="radio"],input[type="checkbox"]{margin:4px 0 0;margin-top:1px \9;*margin-top:0;line-height:normal}input[type="file"],input[type="image"],input[type="submit"],input[type="reset"],input[type="button"],input[type="radio"],input[type="checkbox"]{width:auto}select,input[type="file"]{height:30px;*margin-top:4px;line-height:30px}select{width:170px;background-color:#fff;border:1px solid #ccc}select[multiple],select[size]{height:auto}select:focus,input[type="file"]:focus,input[type="radio"]:focus,input[type="checkbox"]:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.uneditable-input,.uneditable-textarea{color:#999;cursor:not-allowed;background-color:#fcfcfc;border-color:#ccc;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.025);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.025);box-shadow:inset 0 1px 2px rgba(0,0,0,0.025)}.uneditable-input{overflow:hidden;white-space:nowrap}.uneditable-textarea{width:auto;height:auto}input:-moz-placeholder,textarea:-moz-placeholder{color:#999}input:-ms-input-placeholder,textarea:-ms-input-placeholder{color:#999}input::-webkit-input-placeholder,textarea::-webkit-input-placeholder{color:#999}.radio,.checkbox{min-height:20px;padding-left:20px}.radio input[type="radio"],.checkbox input[type="checkbox"]{float:left;margin-left:-20px}.controls>.radio:first-child,.controls>.checkbox:first-child{padding-top:5px}.radio.inline,.checkbox.inline{display:inline-block;padding-top:5px;margin-bottom:0;vertical-align:middle}.radio.inline+.radio.inline,.checkbox.inline+.checkbox.inline{margin-left:10px}.input-mini{width:60px}.input-small{width:90px}.input-medium{width:150px}.input-large{width:210px}.input-xlarge{width:270px}.input-xxlarge{width:530px}input[class*="span"],select[class*="span"],textarea[class*="span"],.uneditable-input[class*="span"],.row-fluid input[class*="span"],.row-fluid select[class*="span"],.row-fluid textarea[class*="span"],.row-fluid .uneditable-input[class*="span"]{float:none;margin-left:0}.input-append input[class*="span"],.input-append .uneditable-input[class*="span"],.input-prepend input[class*="span"],.input-prepend .uneditable-input[class*="span"],.row-fluid input[class*="span"],.row-fluid select[class*="span"],.row-fluid textarea[class*="span"],.row-fluid .uneditable-input[class*="span"],.row-fluid .input-prepend [class*="span"],.row-fluid .input-append [class*="span"]{display:inline-block}input,textarea,.uneditable-input{margin-left:0}.controls-row [class*="span"]+[class*="span"]{margin-left:20px}input.span12,textarea.span12,.uneditable-input.span12{width:926px}input.span11,textarea.span11,.uneditable-input.span11{width:846px}input.span10,textarea.span10,.uneditable-input.span10{width:766px}input.span9,textarea.span9,.uneditable-input.span9{width:686px}input.span8,textarea.span8,.uneditable-input.span8{width:606px}input.span7,textarea.span7,.uneditable-input.span7{width:526px}input.span6,textarea.span6,.uneditable-input.span6{width:446px}input.span5,textarea.span5,.uneditable-input.span5{width:366px}input.span4,textarea.span4,.uneditable-input.span4{width:286px}input.span3,textarea.span3,.uneditable-input.span3{width:206px}input.span2,textarea.span2,.uneditable-input.span2{width:126px}input.span1,textarea.span1,.uneditable-input.span1{width:46px}.controls-row{*zoom:1}.controls-row:before,.controls-row:after{display:table;line-height:0;content:""}.controls-row:after{clear:both}.controls-row [class*="span"],.row-fluid .controls-row [class*="span"]{float:left}.controls-row .checkbox[class*="span"],.controls-row .radio[class*="span"]{padding-top:5px}input[disabled],select[disabled],textarea[disabled],input[readonly],select[readonly],textarea[readonly]{cursor:not-allowed;background-color:#eee}input[type="radio"][disabled],input[type="checkbox"][disabled],input[type="radio"][readonly],input[type="checkbox"][readonly]{background-color:transparent}.control-group.warning .control-label,.control-group.warning .help-block,.control-group.warning .help-inline{color:#c09853}.control-group.warning .checkbox,.control-group.warning .radio,.control-group.warning input,.control-group.warning select,.control-group.warning textarea{color:#c09853}.control-group.warning input,.control-group.warning select,.control-group.warning textarea{border-color:#c09853;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.warning input:focus,.control-group.warning select:focus,.control-group.warning textarea:focus{border-color:#a47e3c;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e}.control-group.warning .input-prepend .add-on,.control-group.warning .input-append .add-on{color:#c09853;background-color:#fcf8e3;border-color:#c09853}
            #generar{
                border-radius: 5px;
            	color: #606060;
                border: solid 1px #b7b7b7;
                background: #fff;
                background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
                background: -moz-linear-gradient(top,  #fff,  #ededed);
                filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed');
                padding: 4px 4px 4px;
                font-size: 100%;
             }
            #titulo {
                font-size: 20px;
                color: #323133;
                font-family: Helvetica Neue, Arial, Helvetica, sans-serif;
                letter-spacing: -1px;
                text-decoration: none; 
                text-shadow: 1px 1px #fff, 0 0 #0e0e0e, 2px 3px 1px #e3e3e3; 
                text-transform: none; 
                word-spacing: -2px;
               }
               
               .white{
                   border-radius: 5px;
                   color: #606060;
                   border: solid 1px #b7b7b7;
                   background: #fff;
                   background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
                   background: -moz-linear-gradient(top,  #fff,  #ededed);
                   filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed');
                   padding: 4px 4px 4px;
                   font-size: 100%;
               }
               
               .white:hover {
                        background: #ededed;
                        background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#dcdcdc));
                        background: -moz-linear-gradient(top,  #fff,  #dcdcdc);
                        filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#dcdcdc');
                }
                .white:active {
                        color: #999;
                        background: -webkit-gradient(linear, left top, left bottom, from(#ededed), to(#fff));
                        background: -moz-linear-gradient(top,  #ededed,  #fff);
                        filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#ffffff');
                }
                
                .white2{
                   margin-top: -10px;
                   border-radius: 5px;
                   color: #606060;
                   border: solid 1px #b7b7b7;
                   background: #fff;
                   background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
                   background: -moz-linear-gradient(top,  #fff,  #ededed);
                   filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed');
                   padding: 4px 4px 4px;
                   font-size: 70%;
               }
               
               .white2:hover {
                        background: #ededed;
                        background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#dcdcdc));
                        background: -moz-linear-gradient(top,  #fff,  #dcdcdc);
                        filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#dcdcdc');
                }
                .white2:active {
                        color: #999;
                        background: -webkit-gradient(linear, left top, left bottom, from(#ededed), to(#fff));
                        background: -moz-linear-gradient(top,  #ededed,  #fff);
                        filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#ffffff');
                }
               
        </style>
        <script>
            
            function calendario() {
                /*funcion para invocar el funcionamiento de el calendario*/
                    $( "#fechaAge" ).datepicker({ 
                     autoSize: true,
                     dayNames: ['Domingo', 'Lunes', 'Martes', 'Mi�rcoles', 'Jueves', 'Viernes', 'S�bado'],
                     dayNamesMin: ['Dom', 'Lu', 'Ma', 'Mi', 'Je', 'Vi', 'Sa'],
                     firstDay: 1,
                     monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
                     monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],
                     dateFormat: 'dd-mm-yy',
                     changeMonth: true,
                     changeYear: true,
                     yearRange: "-90:+0",


                    });
            }
            
            function consultarItems(){
                $.ajax({
                    async: true,
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    url: "../../DeteccionN/controlador/sql/condi.php",
                    success: mostrarDatos,
                    timeout: 4000
                });
            }
            
            function mostrarDatos(datos){
                
                rpt = $.parseJSON(datos);
                var resp = "";
                datos = $("#restn");
                resp += "<table align='center' style='font-size:60%;overflow:hidden;border:1px solid #d3d3d3;background:#fefefe;width:100%;margin:auto auto 0;-moz-border-radius:5px; /* FF1+ */-webkit-border-radius:5px; /* Saf3-4 */border-radius:5px;-moz-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);'>\
                            <tr>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                    CONDICIONES\
                                </td>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                    SI\
                                </td>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                    NO\
                                </td>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                    NA\
                                </td>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                   DESCRIPCION\
                                </td>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                   JUSTIFICACION\
                                </td>\
                                <td align=center style='padding:10px 40px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                    <img style='margin-top:-8px;cursor:pointer' title='agregar una nueva condicion' src='../imagen/nuevo.png' width='25' height='25' alt='aceptar' onclick='condicion();'/>\
                                </td> \
                            </tr>";
                var con = 0;
                for(dat in rpt){
                   
                    var nombre= rpt[dat].descripcion;
                    resp += '<tr>\
                                <td style="padding:10px;text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    '+ nombre +'<input type="hidden"  name="txtoidPregunta[]'+ con +'" value="'+ rpt[dat].conoid +'" /><input type="hidden" id="condiciones'+ con +'"  value="'+ nombre +'" /> \
                                </td>\
                                <td align=center style="padding:10px 10px 10px; text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    \<input type="radio" id="res'+ con +'" name="txtres[]'+ con +'" value="1" />\
                                </td> \
                                <td align=center style="padding:10px 10px 10px; text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    \<input type="radio" id="res'+ con +'" name="txtres[]'+ con +'" value="2" />\
                                </td> \
                                <td align=center style="padding:10px 10px 10px; text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    \<input type="radio" id="res'+ con +'" name="txtres[]'+ con +'" value="3" />\
                                </td> \
                                <td style="padding:10px 10px 10px; text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    \<textarea id="obsevaciones'+ con +'" name="texobservaciones[]'+ con +'" rows="4" cols="40"></textarea>\
                                </td> \
                                <td style="padding:10px 10px 10px; text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    \<textarea id="mejora'+ con +'"  name="texmejora[]'+ con +'" rows="4" cols="40"></textarea>\
                                </td> \
                                 <td align="center" style="border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    <table style="font-size:100%;">\
                                        <tr>\
                                            <td align=center >\
                                            </td>\
                                        </tr>\
                                        <tr>\
                                            <td align="center">\
                                                <input type="button" name="soli" id="generar" value="Generar Solicitud" onclick="solicitud('+ con +');"/>\
                                            </td>\
                                        </tr>\
                                    </table>\
                                </td> \
                                </tr>\ ';
                    con++;
                }
                resp += "</table></br>";
                resp += '<input type="hidden" id="tama" name="txtTama" value="'+ con +'" />';
                resp += "<table align=center style='width:100%;'>\
                            <tr>\
                                <td align='right'>\
                                    <input class='white' type='button' value='Registrar Ronda' onclick='validar();'/>\
                                </td>\
                                <td>\
                                    <input class='white' type='button' value='Restablecer' onclick='limpia();'/>\
                                </td>\
                            </tr>\
                         </table></br></br>";
                datos.append(resp);
                necesidades();
            }
            
            function solicitud(posi){
                
                if(document.getElementById("servicio").value == "0"){
                    alertify.alert("SELECCIONE EL SERVICIO", function () {
                        $("#servicio").focus();
                    });
                    return false;
                }
                if(document.getElementById("obsevaciones"+posi).value == ""){
                    alertify.alert("DESCRIBA LA NECESIDAD", function () {
                        $("#obsevaciones"+posi).focus();
                    });
                    return false;
                }
                if(document.getElementById("mejora"+posi).value == ""){
                    alertify.alert("DESCRIBA LA JUSTIFICACION", function () {
                        $("#mejora"+posi).focus();
                    });
                    return false;
                }
                /*if(document.getElementById("necesidad"+posi).value == "0"){
                    alertify.alert("SELECCIONE LA NECESIDAD", function () {
                        $("#necesidad"+posi).focus();
                    });
                    return false;
                }*/
                
                var condicion = document.getElementById("condiciones"+posi).value;
                var obs = document.getElementById("obsevaciones"+posi).value;
                var mejo = document.getElementById("mejora"+posi).value;
                //var nece = document.getElementById("necesidad"+posi).value;
                var serv = document.getElementById("servicio").value;
                var toid = document.getElementById("tipoid").value;
                
                window.open("detecNecesidades.php?serv="+ serv +"&obs="+ obs +"&mejo="+ mejo +"&toid="+ toid +"&con="+ condicion,"","width=600,height=500,scrollbars=yes");
            }
            
            function condicion(){
              window.open("../../DeteccionN/vista/php/condiciones.php","","width=900,height=500,scrollbars=yes");
            }
            function cargarServicio(){
                $.ajax({
                            type: "POST",
                            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                            url: "../../DeteccionN/controlador/sql/servicios.php",
                            success: mostrarSer,
                            timeout: 4000
                        });
            }
            
            function mostrarSer(datos){
                rpt = $.parseJSON(datos);
                
                datos = $("#servicio");
                
                for(dat in rpt ){
                    datos.append("<option value='"+ rpt[dat].OID +"'>"+ rpt[dat].GDPNOMBRE +"</option>");
                }
            }
            function validar(){
                if(document.getElementById("servicio").value == "0"){
                    alertify.alert("Seleccione servicio"), function () {
                        $("#servicio").focus();
                    };
                    return false;
                }
                
                var formulario = document.forms["cond"];
                var grupos = [];
                for (i = 0; elem = formulario.elements[i]; i++) {
                    if (elem.type == "radio") {
                        if (!grupos[elem.name]) {
                            grupos[elem.name] = elem.checked;
                        }
                    }
                }
                for (grupo in grupos) {
                    if (!grupos[grupo]) {
                        alertify.alert("QUEDAN PREGUNTAS SIN CONTESTAR", function () {
                    });
                        return false;
                    }
                }
                
                alertify.confirm("<p>ESTA SEGURO DE REGISTRAR LA RONDA</p>", function (e) {
                    if (e) {
                        var oidage = document.getElementById("ageoid").value; 
                        $.ajax({
                            async: true,
                            type: "POST",
                            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                            url: "../../DeteccionN/controlador/sql/realizarR.php",
                            success: gr,
                            data:{oidage:oidage},
                            timeout: 4000
                        });
                        /*$('#cond').attr( 'action','../../DeteccionN/controlador/sql/guardarRonda.php');
                        $("#cond").submit();*/
                    } else { 
                        $("").focus();
                    }
                    }); 
                    return false; 
            } 
            
            function agendar(){
                document.getElementById("agenda").innerHTML = "<table>\
                                                                    <tr>\
                                                                        <td style='width:78px'>\
                                                                            Fecha: \
                                                                        </td>\
                                                                        <td>\
                                                                            <input type='text' class='reporte_termino' id='fechaAge' name='txtFechaP' value=''/>\
                                                                        </td>\
                                                                        <td>\
                                                                            <input class='white2' type='button' value='Agendar' onclick = 'enviarA()'/>\
                                                                        </td>\
                                                                        <td>\
                                                                            <input class='white2' type='button' value='Cancelar' onclick='cancelar()'/>\
                                                                        </td>\
                                                                    </tr>\
                                                               </table>";
                 calendario();  
            }
            
            function cancelar(){
                $("#agenda").text("");
                $("#servicio").attr("","0");
            }
            
            function necesidades(){
                $.ajax({
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    url: "../../DeteccionN/controlador/sql/necesidades.php",
                    success: mostrarNec,
                    timeout: 4000
                });
             }


             function mostrarNec(dato){
                 rpt = $.parseJSON(dato);
                 var tama = document.getElementById("tama").value;
                 for(var i = 0; i < tama; i++){
                     dato = $("#necesidad"+i);
                     for(r in rpt){
                        dato.append("<option value='"+ rpt[r].necoid +"'>"+ rpt[r].necnombre +"</option>");
                        document.getElementById("tipoid").value = rpt[r].tipoid;
                     }
                 }
             }
             
             function enviarA(){
                 if($("#servicio").val() === "0"){
                    alertify.alert("SELECCIONE SERVICIO", function () {
                        $("#servicio").focus();
                    });
                    return false;
                }
                 if($("#fechaAge").val() === ""){
                    alertify.alert("SELECCIONE FECHA", function () {
                        $("#fechaAge").focus();
                    });
                    return false;
                }
                 alertify.confirm("<p>ESTA SEGURO DE AGENDAR LA RONDA</p>", function (e) {
                    if (e) {
                        agenda();
                    } 
                    else { 
                    }
                }); 
                return false;
            }
             
             
             function agenda(){
                 
                 var serv = document.getElementById("servicio").value;
                 var fech = document.getElementById("fechaAge").value;
               
                $.ajax({
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    url: "../../DeteccionN/controlador/sql/guardarA.php",
                    success: mostrarM,
                    data:{serv:serv,fech:fech},
                    timeout: 4000
                });
             }
             
             function mostrarM(){
                 alertify.success("la ronda se agendo satisfactoriamente");
                 $("#agenda").text("");
                 document.getElementById("servicio").value = "0";
                 exisagen();
             }
             
             function exisagen(){
                 
                 $.ajax({
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    url: "../../DeteccionN/controlador/sql/exisagen.php",
                    success: mostrarRA,
                    timeout: 4000
                });
             }
             
             function abrirVentana(){
                window.open("../../DeteccionN/vista/php/agenda.php","","width=1000,height=500,scrollbars=yes");
             }
             
             function mostrarRA(res){
                  rpt = $.parseJSON(res);
                  var respuesta = "";
                  for(re in rpt){
                      respuesta = rpt[re].res;
                  }
                  if(respuesta != "0"){
                      document.getElementById("agendadas").innerHTML = '<img style="margin-top:-8px;cursor:pointer" title="tiene rondas agendadas" src="../imagen/agendar_1.png" width="30" height="30" alt="aceptar" onclick="abrirVentana();"/>';
                  }
             }
             
             function avisoAgen(fecha,oidser){
                document.getElementById("avisor").innerHTML = "<font color='#0080FF'>Ronda programada para "+ fecha +"</font>";
                document.getElementById("servicio").value = oidser;
                $("#restn").text("");
                consultarItems();
             }
             
             function recargar(){
                 document.location.reload();
             }
             
             function val(posi,valor){
                 if(valor == "1" || valor == "3"){
                   document.getElementById("obsevaciones"+posi).disabled = true;
                   document.getElementById("obsevaciones"+posi).disabled = true;
                 }
             }
             
             function gr(){
                 $('#cond').attr( 'action','../../DeteccionN/controlador/sql/guardarRonda.php');
                 $("#cond").submit();
             }
             
             function ejecutarR(){
                
             }
             
             function mostrarRonda(ageoid){
                var oidage = ageoid;
                $.ajax({
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    url: "../../DeteccionN/controlador/sql/datosRonda.php",
                    success: mRonda,
                    data:{oidage:oidage},
                    timeout: 4000
                });
             }
             
             function mRonda(datos){
                 rpt = $.parseJSON(datos);
                var resp = "";
                $("#restn").text("");
                datos = $("#restn");
                resp += "<table align='center' style='font-size:60%;overflow:hidden;border:1px solid #d3d3d3;background:#fefefe;width:100%;margin:auto auto 0;-moz-border-radius:5px; /* FF1+ */-webkit-border-radius:5px; /* Saf3-4 */border-radius:5px;-moz-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);'>\
                            <tr>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                    CONDICIONES\
                                </td>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                    SI\
                                </td>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                    NO\
                                </td>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                    NA\
                                </td>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                   DESCRIPCION\
                                </td>\
                                <td align=center style='font-size:100%;padding:10px 10px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                   JUSTIFICACION\
                                </td>\
                                <td align=center style='padding:10px 40px 10px; text-align:center;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe)); background:#e8eaeb;'>\
                                       <img style='margin-top:-8px;cursor:pointer' title='agregar una nueva condicion' src='../imagen/nuevo.png' width='25' height='25' alt='aceptar' onclick='condicion();'/>\
                                   </td> \
                            </tr>";
                var con = 0;
                for(dat in rpt){
                   
                    var nombre= rpt[dat].condescri;
                    var res = rpt[dat].respuesta;
                    if(res == '1'){
                        var respues = 'checked';
                    }else{
                        respues = '';
                    }
                    
                    if(res == '2'){
                        var respues2 = 'checked';
                    }else{
                        respues2 = '';
                    }
                    
                    if(res == '3'){
                        var respues3 = 'checked';
                    }else{
                        respues3 = '';
                    }
                    
                    
                    resp += '<tr>\
                                <td style="padding:10px;text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    '+ nombre +'<input type="hidden"  name="txtoidPregunta[]'+ con +'" value="'+ rpt[dat].conoid +'" /><input type="hidden" id="condiciones'+ con +'"  value="'+ nombre +'" /> \
                                </td>\
                                <td align=center style="padding:10px 10px 10px; text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    \<input type="radio" '+ respues +' id= id="res'+ con +'"  name="txtres[]'+ con +'" value="1" />\
                                </td> \
                                <td align=center style="padding:10px 10px 10px; text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    \<input type="radio" '+ respues2 +' id= id="res'+ con +'"  name="txtres[]'+ con +'" value="2" />\
                                </td> \
                                <td align=center style="padding:10px 10px 10px; text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    \<input type="radio" '+ respues3 +' id= id="res'+ con +'"  name="txtres[]'+ con +'" value="3" />\
                                </td> \
                                <td style="padding:10px 10px 10px; text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    \<textarea id="obsevaciones'+ con +'" name="texobservaciones[]'+ con +'" rows="4" cols="40">' + rpt[dat].resobserv + '</textarea>\
                                </td> \
                                <td style="padding:10px 10px 10px; text-align:centert;border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    \<textarea id="mejora'+ con +'"  name="texmejora[]'+ con +'" rows="4" cols="40">' + rpt[dat].resmejora + '</textarea>\
                                </td> \
                                <td align="center" style="border-top:1px solid #e0e0e0; border-right:1px solid #e0e0e0;background: -moz-linear-gradient(100% 25% 90deg, #fefefe, #f9f9f9);background: -webkit-gradient(linear, 0% 0%, 0% 25%, from(#f9f9f9), to(#fefefe));">\
                                    <table style="font-size:100%;">\
                                        <tr>\
                                            <td align=center >\
                                            </td>\
                                        </tr>\
                                        <tr>\
                                            <td align="center">\
                                                <input type="button" name="soli" id="generar" value="Generar Solicitud" onclick="solicitud('+ con +');"/>\
                                            </td>\
                                            <td align="center">\
                                                <input type="hidden" name="txtoidres[]" id="oidres'+con+'" value="'+rpt[dat].resoid+'" />\
                                            </td>\
                                        </tr>\
                                    </table>\
                                </td> \
                                </tr>\ ';
                    con++;
                }
                resp += "</table></br>";
                resp += '<center><table>\
                            <tr>\
                                <td align="right">\
                                     <input class="white" type="button" value="Editar Ronda" onclick="validarE();"/>\
                                </td>\
                                <td>\
                                    <input class="white" type="button" value="Restablecer" onclick="limpia();"/>\
                                </td>\
                            </tr>\
                        </table></br></center>';
                datos.append(resp);
             }
             
             function limpia(){
                 $("#avisor").text("");
                 $("#restn").text("");
                 $("#servicio").attr('value','0');
                 consultarItems();
             }
             
             function servi(ser_oid){
                 $("#servicio").attr('value',ser_oid);
             }
             function validarE(){
                if(document.getElementById("servicio").value == "0"){
                    alertify.alert("Seleccione servicio"), function () {
                        $("#servicio").focus();
                    };
                    return false;
                }
                
                var formulario = document.forms["cond"];
                var grupos = [];
                for (i = 0; elem = formulario.elements[i]; i++) {
                    if (elem.type == "radio") {
                        if (!grupos[elem.name]) {
                            grupos[elem.name] = elem.checked;
                        }
                    }
                }
                for (grupo in grupos) {
                    if (!grupos[grupo]) {
                        alertify.alert("QUEDAN PREGUNTAS SIN CONTESTAR", function () {
                    });
                        return false;
                    }
                }
                
                alertify.confirm("<p>ESTA SEGURO DE REGISTRAR LA RONDA</p>", function (e) {
                    if (e) {
                        $('#cond').attr( 'action','../../DeteccionN/controlador/sql/editarRonda.php');
                        $("#cond").submit();
                    } else { 
                        $("").focus();
                    }
                    }); 
                    return false; 
            }
                
        </script>
   </head>
    <body onload="consultarItems();cargarServicio();exisagen();">
        <form id="cond" method="post" >
            <table>
                <tr>
                    <td align="center" colspan="9">
                        <label id="titulo">REGISTRO DE IDENTIFICACIÓN DE NECESIDADES </label>
                </tr>
            </table>
            <table style="font-size:90%">
                <tr>
                    <td>
                        <div id="avisor">
                            
                        </div>
                    </td>
                </tr>
            </table>
            </br>
            <table style="width:70%">
                <tr>
                    <td>
                        <table>
                           <tr>
                                <td>
                                    Servicio:
                                </td>
                                <td>
                                    <table>
                                        <td>
                                            <select name="txtServicio" id="servicio">
                                                <option value="0">Seleccione</option>
                                            </select>
                                        </td>
                                        <td>
                                            <img style="margin-top:-8px;cursor:pointer" title="agendar ronda" src="../imagen/agendar.png" width="25" height="25" alt="aceptar" onclick="agendar();"/>
                                       </td>
                                       <td>
                                           <div id="agendadas"></div>
                                       </td>
                                    </table>
                                </td> 
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <div id="agenda">
                                        
                                    </div>
                                </td>
                            </tr>
                         </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div id="restn">
                        </div>
                    </td>
                </tr>
            </table>
            <!--oid tipo de necesiadad-->
            <input type="hidden" id="tipoid" name="txtTipoid" value="" />
            <!--oid de la ronda agendada (ageoid)-->
            <input type="hidden" id="ageoid" name="txtAgeoid" value="" />
        </form>
    </body>
</html>

<!--combo de necesidades
    
    <tr>\
        <td align=center >\
            <select id="necesidad'+ con +'" name="cnNecesidad" style="font-size:100%;width:95px">\
                <option value="0">Seleccione</option>\
            </select>\
        </td>\
    </tr>\
-->